import xlrd
#导入获取文件路径的方法
from common.public_path import file_path
from utils.read_yaml import Read_Yaml
read_yaml=Read_Yaml()
class Read_Excel():

    def __init__(self):
        #获取excel表格的列
        self.caseid=0
        self.describe=1
        self.url=2
        self.method=3
        self.params=4
        self.expect=5

    def get_sheet(self):
        open_excel=xlrd.open_workbook(file_path('data','Data.xlsx'))
        return open_excel.sheet_by_index(0)

    def get_value(self,row,col):
        return self.get_sheet().cell_value(row,col)

    def get_caseid(self,row):
        return  self.get_value(row,self.caseid)

    def get_url(self,row):
        return self.get_value(row,self.url)

    #获取映射方法
    def get_method(self,row):
        return self.get_value(row,self.method)

    #获取请求体的映射参数
    def get_data(self,row):
        return self.get_value(row,self.params)

    def get_body(self,row):
        return read_yaml.read_yaml_list('data','data.yaml')[0][self.get_data(row)]

    def get_body1(self,row):
        return read_yaml.read_yaml_dict('data','data_new.yaml')[self.get_data(row)]

    #获取预期结果
    def get_expect(self,row):
        return self.get_value(row,self.expect)

if __name__ == '__main__':
    read_excel=Read_Excel()
    # print(read_excel.get_url(1))
    # print(read_excel.get_expect(1))
    # print(read_excel.get_data(1))
    print(read_excel.get_body(1))
